#include <stdio.h>

#include "edge.h"
#include "vertex.h"

Edge::Edge(Vertex* endVertex, Edge* currentEdge, int weight)
{
    this->end_ = endVertex;
    this->next_ = currentEdge;
    this->weight_ = weight;
}

Edge::~Edge()
{
    if (this->next_)
        delete this->next_;
    this->next_ = 0;
}

Vertex* Edge::getEnd()
{
    return this->end_;
}

Edge* Edge::getNext()
{
    return this->next_;
}

int Edge::getWeight()const
{
    return this->weight_;
}

void Edge::print()
{
    printf("%d - %d \n", this->end_->getId(), this->weight_);
    if (this->next_)
        this->next_->print();
}

void Edge::insertNext(int weight, Vertex* end, Edge* next)
{
    if (!this->next_)
        this->next_ = new Edge(end, next, weight);
    else
        this->next_->insertNext(weight, end, next);
}
